import { getUserDetailByIdApi } from '@/api/user'
import { saveUserDetailByIdApi } from '@/api/employees'
export default {
  data() {
    return {
      userInfo: {}
    }
  },
  created() {
    this.getUserDetailById()
  },
  methods: {
    async getUserDetailById() {
      try {
        const res = await getUserDetailByIdApi(this.$route.params.id)
        this.userInfo = res.data // 保存全量数据 当修改信息时,及时更新数据
      } catch (error) {
        console.log(error)
      }
    },
    async upDate() {
      try {
        await saveUserDetailByIdApi(this.userInfo)
        if (this.$store.state.user.userInfo.userId === this.userId) {
          this.$store.dispatch('user/getPhoto', this.userId)
        }
        this.$notify({
          type: 'success',
          title: '成功',
          message: '更新员工信息成功!',
          offset: 100
        })
      } catch (error) {}
    }
  }
}
